package com.ruoyi.app.controller;

import com.ruoyi.system.domain.TBanner;
import com.ruoyi.system.domain.TCoupon;
import com.ruoyi.system.domain.TUserCoupon;
import com.ruoyi.system.service.ITCouponService;
import com.ruoyi.system.service.ITUserCouponService;
import com.ruoyi.utils.AjaxResult;
import com.ruoyi.utils.AppUserUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "小程序端-优惠卷")
@RestController
@RequestMapping("/app/coupon")
public class CouponController {

    @Autowired
    private ITCouponService tCouponService;
    @Autowired
    private ITUserCouponService tUserCouponService;

    /**
     * 获取用户优惠卷
     */
    @ApiOperation("获取用户优惠卷")
    @PostMapping("/getCouponByUserId")
    public AjaxResult<TCoupon> getCouponByUserId() {
        List<TCoupon> list = tUserCouponService.selectTUserCouponList(AppUserUtils.getAppUserId());
        return AjaxResult.success(list);
    }


    /**
     * 查询用户优惠卷列表
     */
    @ApiOperation("获取系统发放用户未领取的优惠卷")
    @GetMapping("/list")
    public AjaxResult<TCoupon> list() {
        List<TCoupon> list = tUserCouponService.selectUserNot(AppUserUtils.getAppUserId());
        return AjaxResult.success(list);
    }


    /**
     * 查询用户优惠卷列表
     */
    @ApiOperation("用户领取领取优惠卷")
    @GetMapping("/save")
    public AjaxResult save(TUserCoupon tUserCoupon) {
        tUserCoupon.setUserId(AppUserUtils.getAppUserId());
        tUserCouponService.insertTUserCoupon(tUserCoupon);
        return AjaxResult.success();
    }
}

